package com.yonyou.framework.library.common.log;

import android.util.Log;


/**
 * 作者：joseph_l on 14/12/15 13:49
 * 邮箱：ljt@yonyou.com
 */
public class XmlLog {
    public static void printXml(String tag, String xml,String headString) {

        if (xml != null) {
            xml = XmlLog.formatXML(xml);
            xml = headString + "\n" + xml;
        } else {
            xml = headString + Elog.NULL_TIPS;
        }

        Elog.printLine(tag, true);
        String[] lines = xml.split(Elog.LINE_SEPARATOR);
        for (String line : lines) {
            if (!Elog.isEmpty(line)) {
                Log.d(tag, "║ " + line);
            }
        }
        Elog.printLine(tag, false);
    }

    public static String formatXML(String inputXML) {
//        XMLWriter writer = null;
        String requestXML = null;
//        try {
//            SAXReader reader = new SAXReader();
//            Document document = reader.read(new StringReader(inputXML));
//            StringWriter stringWriter = new StringWriter();
//            OutputFormat format = new OutputFormat(" ", true);
//            writer = new XMLWriter(stringWriter, format);
//            writer.write(document);
//            writer.flush();
//            requestXML = stringWriter.getBuffer().toString();
//        } catch (IOException e) {
//            return inputXML;
//        } catch (DocumentException e) {
//            return inputXML;
//        } finally {
//            if (writer != null) {
//                try {
//                    writer.close();
//                } catch (IOException e) {
//                    return inputXML;
//                }
//            }
//        }

        return requestXML;
    }
}
